<?php
session_start(); 
include("conf/connect.php");

  $user_name = $_POST["data"]["userName"] ;
  $user_password = $_POST["data"]["upass"];
  
	 $sql_data = "SELECT * from user WHERE name = '$user_name' and user_passward = '$user_password'";
	 $result = mysql_query($sql_data);
	 $userData = mysql_fetch_array($result);
	 $totalNumberOfRow = mysql_num_rows($result);
	 
	if ($totalNumberOfRow == 1 ){
			$_SESSION['userName']="$user_name";
			$_SESSION['user_chpass']=$user_name;
			$_SESSION['user_id'] = $userData['id'];
			/*$user_id = $userData['id'];
			
			$sql_log = "INSERT INTO log (id, user_id, status)  VALUES ('','$user_id','0')";
			$result_log = mysql_query($sql_log);*/
			
			if($userData['access'] == '2'){
				if($user_name==$user_password){
					header("location: changepassword.php");
				}
				else{
					header( 'location: location.php' );
				}
			}
			else if($userData['access'] == '1'){
				$_SESSION['adminUser']=1;
				header( 'location: admin/index.php' );
			}
			
			//echo $sql_log = "INSERT INTO log  (id, user_id, status)  VALUES ('',$userData['id'],'0')";
			//$result_log = mysql_query($sql_log);
	}
	else{
			$_SESSION['check']=1;
			header( 'location:logged.php');
	}

?>